﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Nhibernate;
using NHibernate.Criterion;
using NHibernate;

namespace Bussiness.Service
{
    public class Catelogy_Service
    {

        public void save_Catelogy_Product(CateloriesProduct catelogy){
            new HibernateDAO<CateloriesProduct, String>().SaveOrUpdate(catelogy);
        }

        public List<CateloriesProduct> getCateloriesProductParent()
        {
            HibernateDAO<CateloriesProduct, String> dao = new HibernateDAO<CateloriesProduct, String>();
            dao.addSearchCriteria(Expression.IsNull("ParentId"));
            return dao.getByCriterion();
        }

        public List<CateloriesProduct> getCatelogiesProductChild(int parentID)
        {
            HibernateDAO<CateloriesProduct, String> dao = new HibernateDAO<CateloriesProduct, String>();
            dao.addSearchCriteria(Expression.Eq("ParentId", parentID));
            return dao.getByCriterion();
        }

        public List<CateloriesProduct> getAllCatelogiesProductChild()
        {
            HibernateDAO<CateloriesProduct, String> dao = new HibernateDAO<CateloriesProduct, String>();
            dao.addSearchCriteria(Expression.IsNotNull("ParentId"));
            return dao.getByCriterion();
        }



        public CateloriesProduct getCatelogy(int idChild)
        {
            HibernateDAO<CateloriesProduct, String> dao = new HibernateDAO<CateloriesProduct, String>();
            dao.addSearchCriteria(Expression.Eq("ID", idChild));

            List<CateloriesProduct> temp = dao.getByCriterion();

            foreach (CateloriesProduct sv in temp)
            {
                return sv;
            }
            return null;
        }


        //--------------------------- Artical --------------------------------
        public void save_Catelogy_Artical(CatelogriesArticle catelogy)
        {
            new HibernateDAO<CatelogriesArticle, String>().SaveOrUpdate(catelogy);
        }


        public List<CatelogriesArticle> getCateloriesArticalParent()
        {
            HibernateDAO<CatelogriesArticle, String> dao = new HibernateDAO<CatelogriesArticle, String>();
            dao.addSearchCriteria(Expression.IsNull("ParentId"));
            return dao.getByCriterion();
        }

        public List<CatelogriesArticle> getAllCatelogiesArticalChild()
        {
            HibernateDAO<CatelogriesArticle, String> dao = new HibernateDAO<CatelogriesArticle, String>();
            dao.addSearchCriteria(Expression.IsNotNull("ParentId"));
            return dao.getByCriterion();
        }


        public List<CatelogriesArticle> getAllCatelogiesArticalChild(int id_parent)
        {
            HibernateDAO<CatelogriesArticle, String> dao = new HibernateDAO<CatelogriesArticle, String>();
            dao.addSearchCriteria(Expression.Eq("ParentId", id_parent));
            return dao.getByCriterion();
        }



        public CatelogriesArticle getCatelogyArtical(int idChild)
        {
            HibernateDAO<CatelogriesArticle, String> dao = new HibernateDAO<CatelogriesArticle, String>();
            dao.addSearchCriteria(Expression.Eq("ID", idChild));

            List<CatelogriesArticle> temp = dao.getByCriterion();

            foreach (CatelogriesArticle sv in temp)
            {
                return sv;
            }
            return null;
        }
    }
}
